/*
 * Created by SharpDevelop.
 * User: David
 * Date: 2006-11-26
 * Time: 23:20
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Collections.Generic;

namespace Labb4.Media.Graphics
{
	/// <summary>
	/// A container class for the frame information about a sprite entity
	/// </summary>
	public class Animation
	{
		#region members
		
		/// <summary>
		/// The frame numbers that makes up this animation
		/// </summary>
		private List<int>			m_Frames;
		/// <summary>
		/// The display time for a frame. Unit is (ms)
		/// </summary>
		private readonly int		m_Length;
		/// <summary>
		/// With this bool you can set if the animation can be stopped any time,
		/// or if it has to play to the final frame in the List before a new animation
		/// can start playing
		/// </summary>
		private readonly bool		m_MustFinish;
		
		#endregion
		
		#region constructor
		
		/// <summary>
		/// Constructor, initializes members
		/// </summary>
		/// <param name="length">The length of one frame in milliseconds</param>
		/// <param name="mustFinish">Whether or not this animation has to play to the end or not</param>
		public Animation(int length, bool mustFinish)
		{
			m_Frames = new List<int>();
			
			m_Length = length;
			m_MustFinish = mustFinish;
		}
		
		#endregion
		
		#region methods
		
		/// <summary>
		/// Adds a frame number (one from a spritemap) to this animation sequence
		/// </summary>
		/// <param name="frame"></param>
		public void AddFrame(int frame)
		{
			m_Frames.Add(frame);
		}
		
		#endregion
		
		#region properties
		
		/// <summary>
		/// The number of frames in this animation sequence (get)
		/// </summary>
		public int Count
		{
			get
			{
				return m_Frames.Count;
			}
		}
		
		/// <summary>
		/// The frame at [index], -1 if [index] is out of range (get)
		/// </summary>
		public int this[int index]
		{
			get
			{
				int frame = -1;
				
				if(m_Frames.Count > index)
				{
					frame = m_Frames[index];
				}
				
				return frame;
			}
		}
		
		/// <summary>
		/// The display time for a frame. Unit is (ms) (get)
		/// </summary>
		public int Length
		{
			get
			{
				return m_Length;
			}
		}
		
		/// <summary>
		/// Determines if this animation should be allowed to stop at any time,
		/// or if it has to play to the end before being stopped (get)
		/// </summary>
		public bool MustFinish
		{
			get
			{
				return m_MustFinish;
			}
		}
		
		#endregion
	}
}
